﻿/***********************************************************************
 *            Project: CoreCms.Net                                     *
 *                Web: https://CoreCms.Net                             *
 *        ProjectName: 核心内容管理系统                                *
 *             Author: 大灰灰                                          *
 *              Email: JianWeie@163.com                                *
 *         CreateTime: 2020-03-05 1:54:55
 *        Description: 暂无
 ***********************************************************************/


using CoreCms.Net.Model.FromBody;
using System;
using System.Collections.Generic;

namespace CoreCms.Net.Utility.Helper
{
    /// <summary>
    /// 商品规格sku计算
    /// </summary>
    public class SkuHelper
    {
        public static String[] process(string[][] sku)
        {
            int len = sku.Length;
            if (len >= 2)
            {
                var s1 = sku[0];
                int len1 = s1.Length;
                var s2 = sku[1];
                int len2 = s2.Length;

                int len3 = len1 * len2;
                int index = 0;
                string[] items = new string[len3];
                for (int i = 0; i < len1; i++)
                {
                    for (int j = 0; j < len2; j++)
                    {
                        items[index] = sku[0][i] + "," + sku[1][j];
                        index++;
                    }
                }
                // 将新组合的数组并到原数组中
                string[][] newArr = new string[len - 1][];
                for (int i = 2; i < sku.Length; i++)
                {
                    newArr[i - 1] = sku[i];
                }
                newArr[0] = items;
                return process(newArr);
            }
            else
            {
                return (String[])sku[0];
            }
        }


        /// <summary>
        /// 非通用sku组合方法
        /// 支持出颜色和尺码的sku组合,要在外面做判断 然后提示
        /// 然后必须颜色放前面，尺码放后面
        /// </summary>
        /// <param name="listarr"></param>
        /// <returns></returns>

        public static List<SpFormSerializeArray> processSpe(List<List<FormSerializeArray>> listarr)
        {
            List<SpFormSerializeArray> rel = new List<SpFormSerializeArray>();
            //支持出颜色和尺码的sku组合
            foreach (var item in listarr[0])
            {
                foreach (var subitem in listarr[1])
                {
                    var sform=new SpFormSerializeArray();
                    sform.skusize = subitem;
                    sform.skucolor = item;
                    sform.str = "颜色:" + item.value + ",尺码:" + subitem.value;
                    rel.Add(sform);
                }

            }
            return rel;


        }




    }

    public class skuVM
    { 
        public string str { set; get; }

        public int id { set; get; }
    }
}
